﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace LingDingSoft.Http
{
    public class JsonBodyWriter : IBodyWriter
    {
        private string _content;
        private Encoding _coding;
        public JsonBodyWriter(string content, Encoding coding)
        {
            _content = content;
            _coding = coding;

        }
        public JsonBodyWriter(string content)
        {
            _content = content;
            _coding = AppConfig.GetEncoding();

        }
        public void Writer(HttpWebRequest request)
        {

            request.ContentType = "application/json; charset=utf-8";
              
         
             
            request.Method = "post";
            var requestStream = request.GetRequestStream();
            var tempBuffer = _coding.GetBytes(_content);
            requestStream.Write(tempBuffer, 0, tempBuffer.Length);
            requestStream.Close();

        }
    }
}
